package org.upal.springMb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.upal.springMb.domain.admin.User;
import org.upal.springMb.service.admin.UserService;

/**
 * user鎺у埗鍣�
 * @author: Xia YuMing
 * @date: 2014骞�鏈�6鏃ヤ笂鍗�:55:59
 */
@Controller
@RequestMapping(value="/admin/user")
public class UserController {
	@Autowired(required=true)
	private UserService userService;
	
	public UserController() {
		super();
		System.out.println("UserController()");
	}

	//娴嬭瘯璺宠浆
	@RequestMapping(value="/toTest.jspx",method=RequestMethod.POST)
	public String test(){
		System.out.println("test");
		return "myTest";
	}
	/** 璺宠浆鍒扮敤鎴风紪杈戦〉闈�*/
	@RequestMapping(value="toEdit.jspx")
	public String toEdit(){
		return "/user/userEdit";
	}
	/**娣诲姞鐢ㄦ埛淇℃伅*/
	@RequestMapping(value="toSave.jspx",method=RequestMethod.GET)
	public String toSave(User user,Model model){
		try {
			
			userService.saveUser(user);
			model.addAttribute("tip","添加用户名成功！");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("tip","添加用户名失败！");
		}
		return "/user/userEdit";
	}
	
}
